<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">

<ui:composition template="../templates/layout.xhtml">
	<ui:define name="content">
		<h:form prependId="false" id="growlForm">
			<p:growl id="growl" showDetail="true" />
		</h:form>
		<p:ajaxStatus onstart="statusDialog.show()"
			oncomplete="statusDialog.hide()" />
		<p:dialog modal="true" widgetVar="statusDialog" header="Loading..."
			draggable="false" closable="false" resizable="false">
			<h:graphicImage library="images" name="ajax-loader.gif" alt="loader" />
		</p:dialog>
		<h:form id="controlForm" prependId="false">
			<p:panel id="gatewayPanel">
				<f:facet name="header">
					<h:outputText value="Gateway" />
				</f:facet>
				<h:panelGrid columns="2" columnClasses="col1,col2">
				<h:outputLabel value="Status Gateway:" for="gatewayStatus" />
				<h:outputText value="#{gatewayBean.gatewayStatus}" id="gatewayStatus"/>
				</h:panelGrid>
				
				<p:dataTable id="gatewayTable" value="#{gatewayBean.gateways}" var="gateway"
					rendered="#{gatewayBean.dataVisible}" resizableColumns="false">
					<p:column>
						<f:facet name="header">
							<h:outputText value="Gateway ID"/>
						</f:facet>
						<h:outputText value="#{gateway.gatewayId}"/>
					</p:column>
					<p:column>
						<f:facet name="header">
							<h:outputText value="Manufacturer"/>
						</f:facet>
						<h:outputText value="#{gateway.manufacturer}"/>
					</p:column>
					<p:column>
						<f:facet name="header">
							<h:outputText value="Model"/>
						</f:facet>
						<h:outputText value="#{gateway.model}"/>
					</p:column>
					<p:column>
						<f:facet name="header">
							<h:outputText value="Port"/>
						</f:facet>
						<h:outputText value="#{gateway.port}"/>
					</p:column>
					<p:column>
						<f:facet name="header">
							<h:outputText value="Baudrate"/>
						</f:facet>
						<h:outputText value="#{gateway.baudRate}"/>
					</p:column>
					<p:column>
						<f:facet name="header">
							<h:outputText value="SMSC Number"/>
						</f:facet>
						<h:outputText value="#{gateway.smscNumber}"/>
					</p:column>
					<p:column>
						<f:facet name="header">
							<h:outputText value="SIM Pin"/>
						</f:facet>
						<h:outputText value="#{gateway.simPin}"/>
					</p:column>
					<p:column rendered="#{!gatewayBean.started}">
						<f:facet name="header">
							<h:outputText value="Aksi"/>
						</f:facet>
						<p:commandButton value="Start"  action="#{gatewayBean.start}" id="startButton" update="@form :growlForm:growl">
							<f:setPropertyActionListener target="#{gatewayBean.gateway}" value="#{gateway}"/>
						</p:commandButton>
						<p:commandButton id="editButton" icon="ui-icon-pencil"
							action="#{gatewayBean.displayEdit}"
							title="#{messages.label_edit}" oncomplete="createDialog.show()">
							<f:setPropertyActionListener target="#{gatewayBean.gateway}" value="#{gateway}"/>
						</p:commandButton>
						<p:commandButton id="deleteButton" icon="ui-icon-trash"
							oncomplete="deleteDialog.show()" title="#{messages.label_delete}">
							<f:setPropertyActionListener target="#{gatewayBean.gateway}"
								value="#{gateway}" />
						</p:commandButton>
					</p:column>
					<p:column rendered="#{gatewayBean.started}">
						<f:facet name="header">
							<h:outputText value="Aksi"/>
						</f:facet>
						<p:commandButton value="Stop" id="stopButton"
							actionListener="#{gatewayBean.stop}"
							update="@form :growlForm:growl" />
					</p:column>
				</p:dataTable>
				<p:separator/>
				<p:commandButton value="Buat Gateway baru" 
					action="#{gatewayBean.displayNew}" rendered="#{!gatewayBean.started}"
					icon="ui-icon-document" id="createButton" oncomplete="createDialog.show()"/>
			</p:panel>
		</h:form>
		<p:dialog id="createDialog" header="Buat Gateway" 
			modal="true" widgetVar="createDialog" 
			dynamic="true" resizable="true" maximizable="true" showEffect="fade" hideEffect="fade">
     	 <p:outputPanel id="createPanel">
        	<h:form id="createForm">
         		 <h:panelGrid id="createPanelGrid" columns="3" styleClass="dialog" columnClasses="col1,col2,col3">
         		 
         		 <h:outputLabel for="gatewayId" value="ID: "/>
         		 <h:inputText id="gatewayId" value="#{gatewayBean.gateway.gatewayId}" required="true"/>
         		 <p:message for="gatewayId"/>
         		 
         		 <h:outputLabel for="manufacturer" value="Manufacturer: "/>
         		 <h:inputText id="manufacturer" value="#{gatewayBean.gateway.manufacturer}" required="true"/>
         		 <p:message for="manufacturer"/>
         		 
         		 <h:outputLabel for="model" value="Model: "/>
         		 <h:inputText id="model" value="#{gatewayBean.gateway.model}" required="true"/>
         		 <p:message for="model"/>
         		 
         		 <h:outputLabel for="port" value="Port: "/>
         		 <h:inputText id="port" value="#{gatewayBean.gateway.port}" required="true"/>
         		 <p:message for="model"/>
         		 
         		 <h:outputLabel for="baudrate" value="Baudrate: "/>
         		 <h:inputText id="baudrate" value="#{gatewayBean.gateway.baudRate}" required="true"/>
         		 <p:message for="baudrate"/>
         		 
         		 <h:outputLabel for="smsc" value="SMSC Number: "/>
         		 <h:inputText id="smsc" value="#{gatewayBean.gateway.smscNumber}" required="true" />
         		 <p:message for="smsc"/>
         		 
         		  <h:outputLabel for="pin" value="PIN: "/>
         		 <p:inputMask id="pin" value="#{gatewayBean.gateway.simPin}" required="true" mask="9999" />
         		 <p:message for="pin"/>
         		 </h:panelGrid>
         		 <h:panelGrid columns="2" columnClasses="col1,col2">
         		  <p:commandButton id="createSaveButton" value="#{messages.label_save}" action="#{gatewayBean.save}" update=":controlForm :growlForm:growl" oncomplete="createDialog.hide()"/>
         		 <p:commandButton id="createCloseButton" value="#{messages.label_close}" onclick="createDialog.hide()" type="button" action="#{gatewayBean.clear}" />
         		 </h:panelGrid>
       		 </h:form>
      </p:outputPanel>
      </p:dialog>
      <p:confirmDialog id="deleteDialog" widgetVar="deleteDialog"
			message="#{messages.label_delete_record}" showEffect="fade"
			hideEffect="explode" header="#{messages.label_confirm_deletion}"
			severity="alarm">
			<p:outputPanel id="deletePanel">
				<h:form id="deleteForm">
					<p:commandButton id="deleteYesButton" value="#{messages.label_yes}"
						action="#{gatewayBean.delete}"
						update=":controlForm :growlForm:growl"
						oncomplete="deleteDialog.hide()" />
					<p:commandButton id="deleteNoButton" value="#{messages.label_no}"
						onclick="deleteDialog.hide()" type="button" />
				</h:form>
			</p:outputPanel>
		</p:confirmDialog>
	</ui:define>
</ui:composition>
</html>